package vistas.rodamientos;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import app.Odv;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ModificarRodamiento extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JLabel jLabel4;
	private JLabel jLabel5;
	private JTextField jTextFieldStock;
	private JLabel jLabel7;
	private JTextField jTextFieldPrecio;
	private JLabel jLabel6;
	private JButton jButton1;
	private JButton jButton2;
	private JComboBox jComboBox1;
	private JTextField jTextFieldDescripcion;
	private JTextField jTextFieldOrigen;
	private JTextField jTextFieldMarca;
	private JTextField jTextFieldSufijo;
	private JTextField jTextFieldNS;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ModificarRodamiento inst = new ModificarRodamiento();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public ModificarRodamiento() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("NUMERO DE SERIE:");
				jLabel1.setBounds(12, 22, 115, 16);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("SUFIJO: ");
				jLabel2.setBounds(12, 63, 56, 16);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("MARCA: ");
				jLabel3.setBounds(12, 106, 48, 16);
			}
			{
				jLabel4 = new JLabel();
				getContentPane().add(jLabel4);
				jLabel4.setText("ORIGEN: ");
				jLabel4.setBounds(12, 148, 48, 16);
			}
			{
				jLabel5 = new JLabel();
				getContentPane().add(jLabel5);
				jLabel5.setText("CARACTERSTICA:");
				jLabel5.setBounds(12, 194, 105, 16);
			}
			{
				jTextFieldNS = new JTextField();
				getContentPane().add(jTextFieldNS);
				jTextFieldNS.setBounds(145, 19, 85, 23);
			}
			{
				jTextFieldSufijo = new JTextField();
				getContentPane().add(jTextFieldSufijo);
				jTextFieldSufijo.setBounds(145, 54, 85, 23);
			}
			{
				jTextFieldMarca = new JTextField();
				getContentPane().add(jTextFieldMarca);
				jTextFieldMarca.setBounds(145, 99, 85, 23);
			}
			{
				jTextFieldOrigen = new JTextField();
				getContentPane().add(jTextFieldOrigen);
				jTextFieldOrigen.setBounds(145, 145, 85, 23);
			}
			{
				jTextFieldDescripcion = new JTextField();
				getContentPane().add(jTextFieldDescripcion);
				jTextFieldDescripcion.setBounds(145, 191, 85, 23);
			}
			{
				
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				
				
				Odv s= Odv.getinstancia();
				List<Integer>lista=s.rodamientosId();
				
				for(int i:lista)
					jComboBox1.addItem(i);
				
				
				jComboBox1.setBounds(284, 99, 42, 23);
				jComboBox1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jComboBox1.actionPerformed, event="+evt);
						Odv s= Odv.getinstancia();
						
						jTextFieldNS.setText(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getNumeroSerie());
						jTextFieldSufijo.setText(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getSufijo());
						jTextFieldMarca.setText(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getMarca());
						jTextFieldOrigen.setText(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getOrigen());
						jTextFieldDescripcion.setText(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getCaracteristica());
						jTextFieldPrecio.setText(Float.toString(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getPrecio()));
						jTextFieldStock.setText(Integer.toString(s.getRodamiento((Integer) jComboBox1.getSelectedItem()).getStock()));
					
						
						
						
					}
				});
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("GUARDAR");
				jButton1.setBounds(100, 320, 74, 23);
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton1.actionPerformed, event="+evt);
							
						Odv s =Odv.getinstancia();
						s.modificarRodamiento((Integer) jComboBox1.getSelectedItem(), jTextFieldNS.getText(), jTextFieldSufijo.getText(), jTextFieldMarca.getText(), jTextFieldOrigen.getText(), jTextFieldDescripcion.getText(),Float.parseFloat( jTextFieldPrecio.getText()),Integer.parseInt( jTextFieldStock.getText()));
						SeModificoRodamiento v2= new SeModificoRodamiento();
						v2.setVisible(true);
						v2.setLocationRelativeTo(null);
					}
				});
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("FINALIZAR");
				jButton2.setBounds(224, 320, 71, 23);
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton2.actionPerformed, event="+evt);
						dispose();
					}
				});
			}
			{
				jLabel6 = new JLabel();
				getContentPane().add(jLabel6);
				jLabel6.setText("PRECIO: ");
				jLabel6.setBounds(12, 231, 56, 16);
			}
			{
				jTextFieldPrecio = new JTextField();
				getContentPane().add(jTextFieldPrecio);
				jTextFieldPrecio.setBounds(145, 228, 85, 23);
			}
			{
				jLabel7 = new JLabel();
				getContentPane().add(jLabel7);
				jLabel7.setText("STOCK: ");
				jLabel7.setBounds(12, 276, 64, 16);
			}
			{
				jTextFieldStock = new JTextField();
				getContentPane().add(jTextFieldStock);
				jTextFieldStock.setBounds(145, 273, 85, 23);
			}
			pack();
			this.setSize(400, 387);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
